#include <stdio.h>
#include <iostream>
using namespace std;

int GetMaxSum(int array[], int size);

int main()
{
	int array[] = {1, -2, 3, 10, -4, 7, 2, -5};
	int size = sizeof(array) / sizeof(*array);
	
	cout<< GetMaxSum(array, size) <<endl;

	system("pause");
	return 0;
}

int GetMaxSum(int array[], int size)
{
	int max = - (1 << 31);
	int sum = 0;
	
	for (int i = 0; i < size; ++ i)
	{
		sum += array[i];
		if (sum < 0)
		{
			sum = 0;
		}
		if (sum > max)
		{
			max = sum;
		}
	}
	return max;
}